import redis
import logging


class Config(object):
    """项目配置信息"""

    SECRET_KEY = 'KQHFVGUKKVL;PQOIBV9781+i&-#vl984F1FC$V'

    # 数据库配置信息
    SQLALCHEMY_DATABASE_URI = 'mysql://root:mysql@127.0.0.1:3306/information'
    SQLALCHEMY_TRACK_MODIFICATIONS = False  # 关闭数据库修改跟踪
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True  # 会话结束时自动提交,可替代db.session.commit

    # redis配置
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = '6379'

    # session配置
    SESSION_TYPE = 'redis'  # 指定将session添加到redis中
    SESSION_USE_SIGNER = True  # 让cookie中的session加密
    SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT)  # todo 使用redis实例,可选数据库(db = REDIS_NUM)
    PERMANENT_SESSION_LIFETIME = 86400  # 过期时间(1天)

    # 默认日志等级
    LOG_LEVEL = logging.DEBUG


class DevelopmentConfig(Config):
    """开发模式下的配置"""
    DEBUG = True


class ProductionConfig(Config):
    """生产模式下的配置"""
    LOG_LEVEL = logging.ERROR


# 定义配置字典
config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig
}
